<?php
require_once('includes/inc.php');
checkLang($_GET['j']);

$ipaddr=$_SERVER['REMOTE_ADDR'];

// proverka za ip adresa - dokolku se posetuva lokalno so cel da se vidi funkcionalnosta na prikazuvanje uslovi spored lokacijata
if(!contains("192.168.",$ipaddr)) $ipaddr="79.126.231.157";


//den - nok
$dn=daynightC($ipaddr);

$grad=trim(getLoc($ipaddr));

$akey = getAKey();

$link="http://where.yahooapis.com/v1/places.q('".$grad."')?appid=".$akey;

$xmlmap = simplexml_load_file($link);

$xxx = $xmlmap->place;

$woeid = $xxx->woeid;

$long = $xxx->centroid->longitude;

$lat = $xxx->centroid->latitude;

	//zname za jazik
	$lflag = getRFlag();

	// source link
	$link="http://weather.yahooapis.com/forecastrss?w=".$woeid."&u=c";
	
	// zemanje na parametri od
	$src=file_get_contents($link);
	
	if(!(contains("Error",$src)))
	{
	
	//temperatura
	$temp=getAttrib("condition","temp",$src);
	
	//pritisok
	$pritisok=getAttrib("atmosphere","pressure",$src);
	
	//vlaznost
	$vlaznost=getAttrib("atmosphere","humidity",$src);
	
	//vidlivost
	$vid=getAttrib("atmosphere","visibility",$src);
	
	//vetar
	$vetar=getAttrib("wind","speed",$src);
	
	//kod za vremenski uslovi
	$kod=getAttrib("condition","code",$src);
	
	// vremenska sostojba
	$tempcond=getFlag();
		switch($tempcond)
		{
			case 'mk': $cond=getCond($kod,'mak'); break;
			case 'en': $cond=ucfirst(getCond($kod,'eng')); break;
			default: $cond=getCond($kod,'mak'); break;
		}
	}
	else
	{
		$pritisok="";
		$vlaznost="";
		$vid="";
		$vetar="";
		$temp="";
		$kod="";
		$slika="";
		$cond="";
	}
	if($pritisok=="") $pritisok="N/A";
	if($temp=="") $temp="N/A";
	if($vid=="") $vid="N/A";
	if($vetar=="") $vetar="N/A";
	if($vlaznost=="") $vlaznost="N/A";
	if($kod=="") $kod="NA";
	if($vid>="999") { $vid=_CLEAR; $unit2=""; }
	
	// slika soodvetno na uslovite
	$slika="img/$kod.png";
	
	// tekovno vreme
	$vreme=date("H:i");
	
	
	// ako imeto na gradot e pogolemo od 18 karakteri skrati go i dodadi ...
	$gradfull=$grad;
	if(strlen($grad)>18) 
	{
		$gradfull=$grad;
		$grad=substr($grad,0,18);
		$grad.="...";
	}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="jw.css.php?dn=<?php echo $dn; ?>" />
	<script type="text/javascript" src="jweather.js.php?dn=<?php echo $dn; ?>" charset="utf-8"></script>
	<script type="text/javascript" src="http://gettopup.com/releases/latest/top_up-min.js"></script> 
</head>
	<body onLoad="jwlocation.focus()">
<div id="jwwrapper">
	<div id="jwmain">
		<div id="jwheader">
			<div id="jwgrad" title="<?php echo $gradfull; ?>"><?php echo $grad." "; ?></div>
			<div id="jwcas">| <?php echo $vreme."h"; ?></div>
			<div id="jwlang">
			<a href="index.php?j=<?php echo substr($lflag,4,2); ?>"><img src="<?php echo $lflag; ?>"></img></a>
			</div>
			<div id="jwunit"> 
				<a href="#" title="<?php echo _KONVERTIRAJF; ?>" onclick="javascript:convert('F');">°F</a> |
			</div>
		</div>
		<div id="jwcontent">
			<div id="jwmain1">
				<div id="jwlogo"><img src="<?php echo $slika; ?>" alt="<?php echo $cond; ?>" title="<?php echo $cond; ?>"/></div>
				<div id="jwtext"><?php echo $cond; ?><br /> <span id="jwtemp"><?php echo $temp; ?> °C</span></div>
			</div>
			<div id="jwmain2">
				<div id="left">
						<span id="l1"><?php echo _PRITISOK; ?>: <span id="jwpritisok"><?php echo $pritisok; ?> mb</span></span><br />
						<span id="l1"><?php echo _VIDLIVOST; ?>: <span id="jwvid"><?php echo $vid; ?> KM</span></span><br />
				</div>
				<div id="right">					
						<span id="l1"><?php echo _VLAZNOST; ?>: <?php echo $vlaznost; ?> %</span> <br />
						<span id="l1"><?php echo _VETER; ?>: <span id="jwwind"><?php echo $vetar; ?> kph</span></span> <br />
					
				</div>
			</div>
			<div id="jwmain3">
				<a href="map.php?long=<?php echo $long; ?>&lat=<?php echo $lat;?>&temp=<?php echo $temp;?>&kod=<?php echo $kod;?>&cond=<?php echo $cond;?>"
				toptions="width = 400, height = 320, type = iframe, layout = dashboard, resizable=0"
				><?php echo _MAPA; ?></a> | <a href="istorija.php" toptions="width = 640, height = 480, type = iframe, layout = dashboard, resizable=1"><?php echo _ISTORIJA; ?></a>
			</div>
		</div>
	</div>
</div>
<div id="jwsearch">
	<input type="text" class="inputbox" name="jwlocation" id="jwlocation" autocomplete="off" onkeyup="suggest(event);" onkeypress="enter(event);" />
	<input type="submit" class="button" value="<?php echo _BARAJ; ?>" id="submit" name="submit" onclick="getWeather('X','c');" />
</div>
<div id="jwsuggestion">
</div>
</body>
</html>